package com.qiangesoft.blog.controller.manage;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.system.entity.SysMenu;
import com.qiangesoft.blog.system.service.ISysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单管理 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/menu")
@Api(tags = "系统菜单管理-接口")
@RequiredArgsConstructor
public class SysMenuController {

    private final ISysMenuService menuService;

    @GetMapping(value = "/getMenuTree")
    @SaCheckLogin
    @ApiOperation(value = "获取菜单树", httpMethod = "GET", response = ResponseResult.class, notes = "获取菜单树")
    public ResponseResult getMenuTree() {
        List<SysMenu> result = menuService.listMenuTree(menuService.list());
        return ResponseResult.success("获取菜单树成功", result);
    }

    @GetMapping(value = "/getMenuApi")
    @SaCheckLogin
    @ApiOperation(value = "获取所有接口", httpMethod = "GET", response = ResponseResult.class, notes = "获取所有接口")
    public List<SysMenu> listMenuApi(Long id) {
        return menuService.listMenuApi(id);
    }

    @PostMapping(value = "/create")
    @ApiOperation(value = "添加菜单", httpMethod = "POST", response = ResponseResult.class, notes = "添加菜单")
    @OperationLog(value = "添加菜单")
    public void insert(@RequestBody SysMenu menu) {
        menuService.insertMenu(menu);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改菜单", httpMethod = "POST", response = ResponseResult.class, notes = "修改菜单")
    @OperationLog(value = "修改菜单")
    public void update(@RequestBody SysMenu menu) {
        menuService.updateMenu(menu);
    }

    @DeleteMapping(value = "/remove")
    @ApiOperation(value = "删除菜单", httpMethod = "DELETE", response = ResponseResult.class, notes = "删除菜单")
    @OperationLog(value = "删除菜单")
    public void deleteMenuById(Long id) {
        menuService.deleteMenuById(id);
    }
}
